﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace OkTool.Web
{
    public class AshxUtil
    {
        /// <summary>
        /// 读取ashx-json
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static T ReadJson<T>(HttpContext ctx)
        {
            string jsonString;
            using (var reader = new StreamReader(ctx.Request.InputStream))
            {
                jsonString = reader.ReadToEnd();
            }
            // 解析 JSON 数据
            var model = JsonConvert.DeserializeObject<T>(jsonString);
            return model;
        }
    }
}
